package com.netty.LongConnect;

import com.immomo.mcf.util.StringUtils;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufOutputStream;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * @author: sun.hongliang
 * @create: 2019/02/22 18:02
 */
public class MessageEncoder extends MessageToByteEncoder<RequestInfo> {


    @Override
    protected void encode(ChannelHandlerContext ctx, RequestInfo msg, ByteBuf out) throws Exception {
        out.writeByte(msg.getType());
        byte[] info = null;
        if (msg != null && StringUtils.isNotEmpty(msg.getInfo())) {
            info = msg.getInfo().getBytes("utf-8");
            out.writeBytes(info);
        }
    }
}
